using UnityEngine;
namespace CGF
{
    public partial class PanelWithdrawRecords : UIComponentBase, IAwake<UILayer, bool>, IDestroy
    {
        public static void Open()
        {
            UIManagerComponent.instance.OpenUI<PanelWithdrawRecords>(UILayer.Normal, RootComponent.instance, false);
        }

        public static void Close()
        {
            UIManagerComponent.instance.CloseUI<PanelWithdrawRecords>();
        }

        public async void Awake(UILayer layer, bool isFloat)
        {
            await SpawnPrefab("Prefabs/GameUI/PanelWithdrawRecords", layer, isFloat);
            BindProperties(transform);

            BtnBack.SetClick(Close);

            string api = "/v1/withdrawal";
            string listKey = "Results";
            Table.Column[] columns =
            {
                (cell, data) => TimeHelper.Parse2Date(data["created_at"].ToString(), false),
                (cell, data) => data["id"].ToString(),
                (cell, data) => $"<color={Config.NumColor}>{I18N.Currency}<b>{StringHelper.Format2Decimal(Mathf.Abs((int)data["amount"]) * 0.01f)}</b></color>",
                (cell, data) =>
                {
                    //0和1=处理中 2=已失败 3=已到账 4=已拒绝
                    switch ((int)data["state"])
                    {
                        default:
                            return I18N_review;
                        case 2:
                            return I18N_failed;
                        case 3:
                            return I18N_complated;
                        case 4:
                            return I18N_reject;
                    }
                }
            };
            Table.GetComponent<Table>().ReqData(api, listKey, columns);
        }

        public override void OnDestroy()
        {
            base.OnDestroy();
        }

    }
}
